package com.wl.api.common.utils;

import org.apache.commons.lang.StringEscapeUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import lombok.extern.java.Log;


@Component
@Aspect
@Log
public class InjectSqlAOP {

	@Pointcut("@annotation(com.rwy.util.ParamTransfer)")
	public void pointCut() {

	}
	
	@Around("pointCut()")
    public Object test(ProceedingJoinPoint pjp) throws Throwable{
        Object[] args = pjp.getArgs();
        for(int i =0; i < args.length ; i++) {
        	if (!ObjectUtil.isEmpty(args[i]) && args[i].getClass().equals(String.class)) {
        		log.info(" inject sql, string escape parameter: "+ args[i]);
				args[i] = StringEscapeUtils.escapeSql((String) args[i]);
			}
        }
        Object retVal = pjp.proceed(args);
        return retVal;
    }
}
